#include "fileio.h"
#include <QDebug>

FileIO::FileIO()
{

}

void FileIO::write_int(QByteArray *out, quint32 n)
{
    //out->writeRawData((char*)&n,sizeof(quint32));
    char buffer[4];

    buffer[3] = n >> 24;
    buffer[2] = n >> 16;
    buffer[1] = n >> 8;
    buffer[0] = n;

    out->append(buffer,4);
}

void FileIO::insert_int(QByteArray *out,int index, quint32 n)
{
    //out->writeRawData(&n,sizeof(quint32));

    char buffer[4];

    buffer[3] = n >> 24;
    buffer[2] = n >> 16;
    buffer[1] = n >> 8;
    buffer[0] = n;

    out->insert(index,buffer,4);
}


void FileIO::write_short(QByteArray *out, quint16 n)
{
    // out->writeRawData(&n,sizeof(quint16));

    char buffer[2];

    buffer[1] = n >> 8;
    buffer[0] = n;

    out->append(buffer,2);
}

void FileIO::write_chars(QByteArray *out, const char *s)
{
    uint t =0;
    while (s[t]!= 0 && t< 255) {
        t++;
    }

    out->append(s,t);
}

void FileIO::write_chars_bin(QByteArray *out, const char *s, int count)
{
    out->append(s,count);
}
